package com.gzy.xuexiziliao.controller;



import com.gzy.xuexiziliao.common.result.PageResult;
import com.gzy.xuexiziliao.common.result.Result;
import com.gzy.xuexiziliao.pojo.dto.AnonymousDTO;
import com.gzy.xuexiziliao.service.AnonymousPostService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;

@Slf4j
@RestController
@RequestMapping("/anonymous")
public class AnonymousPostController {

    @Autowired
    private AnonymousPostService anonymousPostService;
    /**
     * 添加帖子
     */
    @PostMapping("/add")
    public Result add(@RequestBody AnonymousDTO anonymousDTO) {
        log.info("添加帖子");
        anonymousPostService.saveAnonymousPost(anonymousDTO);
        return Result.success();
    }

    /**
     * 查看帖子
     */
    @GetMapping("/list")
    public Result page(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize,
                       Byte category,
                       @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin,
                       @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end) {
        log.info("分页查询");
        PageResult pageResult = anonymousPostService.page(page,pageSize, category,begin,end);
        return Result.success(pageResult);
    }
}
